<?php
require_once BaseUtil::getModulePath("base") . '/models/BaseDao.php';

class AccountAgentTradeLogDao extends BaseDao {
	protected $_name ;
	protected $joinAgent;

	public function _setup(){
		$this->_name = "account_agent_trade_logs";
		$this->joinAgent = "users";
		parent::_setup();
	}

	public function getTradeLogById($id){//david
		$select=$this->db_r->select();
		$select->from($this->_name,'*');
		$select->joinLeft("users","$this->_name.user_id = $this->joinAgent.id",array("name as uname"));
		$select->where($this->_name . '.id=?',$id);
		$select->where($this->_name . '.is_delete=?',0);
		$sql=$select->__toString();
		return $this->db_r->fetchRow($sql);
	}

	public function insertTradeLog($data){
		$id = $this->insertData($data,true);
		return $id;
	}

//	public function getLastTradeLog($createId){
//		$select=$this->db_r->select();
//		$select->from($this->_name,'*');
//		$select->where($this->_name . '.create_id=?',$createId);
//		$select->where($this->_name . '.is_delete=?',0);
//		$select->order('create_time DESC');
//		$sql=$select->__toString();
//		return $this->db_r->fetchRow($sql);
//	}

	public function updateLastTradeLog($set,$id){
		$where=$this->db_w->quoteInto('id=?',$id);
		$this->updateData($set, $where ,true);
	}

//	public function deleteTradeLog($id){//david
//		$set=array('is_delete'=>1);
//		$where=$this->db_w->quoteInto('id=?',$id);
//		$this->updateData($set, $where);
//	}
//
//	public function updateAccountAgentTradeLogById($data, $id){//david
//		$where=$this->db_w->quoteInto('id=?',$id);
//		//$this->db_w->update($this->_name, $data, $where);
//		$this->updateData($data, $where);
//	}
//
//	public function insertAccountAgentTradeLog($data){//david
//		return $this->insertData($data);
//	}
//	public function todaySupplement($tradetype,$status){
//		$select=$this->db_r->select();
//		$select->from($this->_name,array('sum(trade_sum) as trade_sum'));
//		$select->where($this->_name . '.trade_type in (?)', $tradetype);
//		$select->where($this->_name . '.status =?', $status);
//		$select->where('to_days('.$this->_name . '.create_time) = to_days(?)', date('Y-m-d'));
//		$select->where($this->_name . '.is_delete=?',0);
//		$sql=$select->__toString();
//		return $this->db_r->fetchRow($sql);
//	}
//	public function topTenTrade(){
//		$select=$this->db_r->select();
//		$select->from($this->_name,'*');
//		$select->where($this->_name . '.is_delete=?',0);
//		$select->order('create_time desc');
//		$select->limit(10);
//		$sql=$select->__toString();
//		return $this->db_r->fetchAll($sql);
//	}
//	public function getTradeByYearandType($tradetype){
//		$select=$this->db_r->select();
//		$select->from($this->_name,array('Sum(trade_sum) AS trade_sum','month(create_time) AS month'));
//		$select->where($this->_name . '.is_delete=?',0);
//		$select->where($this->_name . '.trade_type=?',$tradetype);
//		$select->where($this->_name . '.status =?', $tradetype+2);
//		$select->where('year('.$this->_name . '.create_time)=?', date("Y"));
//		$select->group('month(create_time)');
//		$sql=$select->__toString();
//		return $this->db_r->fetchAll($sql);
//	}
//	public function getWithdrawByType(){
//		$select=$this->db_r->select();
//		$select->from($this->_name,array('Sum(trade_sum) AS trade_sum'));
//		$select->where($this->_name . '.is_delete=?',0);
//		$select->where($this->_name . '.trade_type=?',3);
//		$select->where($this->_name . '.status =?', 5);
//		$select->where($this->_name . '.withdraw_type in(?)',array('1','2','3'));
//		$select->where('year('.$this->_name . '.create_time)=?', date("Y"));
//		$sql=$select->__toString();
//		return $this->db_r->fetchAll($sql);
//	}
//	public function getSupplementByType(){
//		$select=$this->db_r->select();
//		$select->from($this->_name,array('Sum(trade_sum) AS trade_sum'));
//		$select->where($this->_name . '.is_delete=?',0);
//		$select->where($this->_name . '.trade_type=?',1);
//		$select->where($this->_name . '.status =?', 3);
//		$select->where($this->_name . '.supplement_type in(?)',array('1','2','3'));
//		$select->where('year('.$this->_name . '.create_time)=?', date("Y"));
//		$sql=$select->__toString();
//		return $this->db_r->fetchAll($sql);
//	}
//	public function getSumTradeByType($tradetype){
//		$select=$this->db_r->select();
//		$select->from($this->_name,array('Sum(trade_sum) AS trade_sum'));
//		$select->where($this->_name . '.is_delete=?',0);
//		$select->where($this->_name . '.trade_type=?',$tradetype);
//		$select->where($this->_name . '.status =?', $tradetype+2);
//		$select->where('year('.$this->_name . '.create_time)=?', date("Y"));
//		$sql=$select->__toString();
//		return $this->db_r->fetchAll($sql);
//	}
//	public function deleteTradeLogByUserId($userid){
//		$set=array('is_delete'=>1);
//		$where=$this->db_w->quoteInto('user_id=?',$userid);
//		$this->updateData($set, $where);
//	}
}
?>